<?php
/*
 * Created on Oct 14, 2008
 *
 * Display the image that is stored in the database.
 */
 
require_once ("dbconnect.php");

$db = dbconnect();

// some basic sanity checks
if(isset($_GET['image']) && is_numeric($_GET['image'])) {

	$image = $_GET['image'];
    // get the image from the db
    $sql = "SELECT image, type FROM images WHERE id=$image";
 
    // the result of the query
   	$result = $db->query($sql);
 
	if ( $result ) {
		
	    while($row = $result->fetchRow()){
	    	$image = $row[0];
	    	$type = $row[1];
		    // set the header for the image
		    header("Content-type: $type");
		    echo $image;
	    }
	}  
    // close the db link
    $db->disconnect();
}
else {
    echo 'Please use a real id number';
} 
?>
